package com.usian.controller;

import com.alibaba.fastjson.JSON;
import com.usian.pojos.User;
import org.apache.kafka.common.protocol.types.Field;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.AliasFor;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class Provider {

    @Autowired
    private KafkaTemplate<String,String>kafkaTemplate;

    @RequestMapping("/send")
    public String send(){
        List<String>addrList=new ArrayList<>();
        User user=new User();
        user.setUsername("张三");
        user.setAge(20);
        addrList.add("北京市");
        addrList.add("天津市");
        addrList.add("陕西");
        user.setAddrList(addrList);

            kafkaTemplate.send("hello-kafka", JSON.toJSONString(user));
            return "success";
    }


}
